package com.lxj.xpopup.impl;

import android.content.Context;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.lxj.xpopup.R;
import com.lxj.xpopup.core.CenterPopupView;

/**
 * Description: 加载对话框
 * Create by dance, at 2018/12/16
 */
public class LoadingPopupView extends CenterPopupView {
    private TextView tv_title;
    private int txtResID;


    /**
     *
     * @param context
     * @param bindLayoutId  layoutId 如果要显示标题，则要求必须有id为tv_title的TextView，否则无任何要求
     */
    public LoadingPopupView(@NonNull Context context, int bindLayoutId,int txtResID) {
        super(context);
        this.bindLayoutId = bindLayoutId;
        this.txtResID = txtResID;
        addInnerContent();
    }

    @Override
    protected int getImplLayoutId() {
        return bindLayoutId != 0 ? bindLayoutId : R.layout._xpopup_center_impl_loading;
    }

    @Override
    protected void initPopupContent() {
        super.initPopupContent();
        tv_title = findViewById(R.id.tv_load);
        getPopupImplView().setElevation(10f);
        ProgressBar progressBar = findViewById(R.id.img_load);
        progressBar.setIndeterminateDrawable(getResources().getDrawable(R.drawable._xpopup_loading_animation));
        setup();
    }
    protected void setup() {
        if(txtResID==0){
            tv_title.setVisibility(GONE);
        }else{
            tv_title.setVisibility(VISIBLE);
            tv_title.setText(txtResID);
        }
//        if (title != null && title.length()!=0 && tv_title != null) {
//            tv_title.setVisibility(VISIBLE);
//            tv_title.setText(title);
//        }
//
    }

    private CharSequence title;

    public LoadingPopupView setTitle(CharSequence title) {
        this.title = title;
        setup();
        return this;
    }
}
